const {
  log
} = require('debug')

module.exports = class user_dao extends require('../model/admin_mod') {
  // 根据关键字获取用户信息
  static async getUsersByTypeAndChar(req, res) {
    const {
      type,
      inputText,
      charType,
      pageSize,
      currPage
    } = req.query

    let data = await this.getUsersByTypeAndCharMod(type, inputText, charType, pageSize, currPage)
    let total = await this.getUsersByTypeAndCharTotal(type, inputText, charType)

    res.json({
      data,
      total: total[0].count
    })
  }

  // 发布公告
  static async announce(req, res) {
    let {
      title,
      classes,
      content,
    } = req.body
    let results = await this.announceMod(title, classes, content)
    res.json(results)
  }

  //获取通知和数量
  static async getAllNotice(req, res) {
    let {
      pageSize,
      currPage
    } = req.query
    let data = await this.getAllNoticeMod(pageSize, currPage)
    let total = await this.getAllNoticeTotal()
    res.json({
      data,
      total: total[0].count
    })
  }

  //获取所有班级
  static async getAllClasses(req, res) {
    let {
      pageSize,
      currPage
    } = req.query
    let data = await this.getAllClassesMod(pageSize, currPage)
    res.json(data)
  }

  //模糊查询班级
  static async getClassesSearch(req, res) {
    let {
      pageSize,
      currPage,
      className
    } = req.query
    let data = await this.getClassesSearchMod(className, pageSize, currPage)
    res.json(data)
  }

  //添加班级
  static async addClasses(req, res) {
    let {
      classes
    } = req.query
    let data = await this.addClassesMod(classes)
    res.json(data)
  }

  //删除公告及涉及的阅读表
  static async delNotice(req, res) {
    let {
      n_id
    } = req.query
    n_id -= 0
    let result = await this.delNoticeMod(n_id)
    result = await this.delReadByNoticeMod(n_id)
    res.json(result)
  }
}